<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html >
<html>
<head>
    <title>智慧社区-登录</title>

    <meta name="description" content="login page" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="shortcut icon" href="${pageContext.request.contextPath}/resource/assets/img/favicon.png" type="image/x-icon">

    <!--Basic Styles-->
    <link href="${pageContext.request.contextPath}/resource/assets/css/bootstrap.min.css" rel="stylesheet" />
    <link href="${pageContext.request.contextPath}/resource/assets/css/font-awesome.min.css" rel="stylesheet" />


    <!--Beyond styles-->
    <link href="${pageContext.request.contextPath}/resource/assets/css/beyond.min.css" rel="stylesheet" />
    <link href="${pageContext.request.contextPath}/resource/assets/css/animate.min.css" rel="stylesheet" />

 
</head>
<body>
	<div class="loading-container" style="display: none;">
        <div class="loading-progress">
            <div class="rotator">
                <div class="rotator">
                    <div class="rotator colored">
                        <div class="rotator">
                            <div class="rotator colored">
                                <div class="rotator colored"></div>
                                <div class="rotator"></div>
                            </div>
                            <div class="rotator colored"></div>
                        </div>
                        <div class="rotator"></div>
                    </div>
                    <div class="rotator"></div>
                </div>
                <div class="rotator"></div>
            </div>
            <div class="rotator"></div>
        </div>
    </div>
 <div class="login-container animated fadeInDown">
        <div class="loginbox bg-white" onkeydown="keyLogin()">
            <div class="loginbox-title">登 录</div>
            
            <div class="loginbox-or">
                <div class="or-line"></div>
            </div>
            <div class="loginbox-textbox">
                <input id="username" type="text" class="form-control" placeholder="用户名（手机号）" />
            </div>
            <div class="loginbox-textbox">
                <input id="password" type="password" class="form-control" placeholder="密码" />
            </div>
            <div class="loginbox-forgot">
                <a href="#" onclick="forgotPwd()">忘记密码？</a>
            </div>
            <div class="loginbox-submit">
                <input type="button" class="btn btn-primary btn-block" value="Login" onclick="doLogin()"/>
            </div>
            <div class="loginbox-signup">
                <a href="register.html">Sign Up With Email</a>
            </div>
        </div>
    </div>

    <!--Basic Scripts-->
    <script src="${pageContext.request.contextPath}/resource/assets/js/jquery-2.0.3.min.js"></script>
    <script src="${pageContext.request.contextPath}/resource/assets/js/bootstrap.min.js"></script>

    <!--Beyond Scripts-->
    <script src="${pageContext.request.contextPath}/resource/assets/js/beyond.js"></script>
    <script type="text/javascript">
    	(function() {
        	$('#username').focus();
        	
			})(jQuery);
    	function forgotPwd(){
    		alert("请联系你的上一级系统管理员");
    	}
    	
    	 function doLogin()
    		{
    			var username = $('#username').val();
    			    var password = $('#password').val();
    			    if($.trim(username)=='' || $.trim(password)=='')
    			    {
    			       return;
    			    }
    			    
    			    $('.loading-container').show();
    			     $.post("login", {username : username,password : password}, 
    			     function(data) {
    			    	 $('.loading-container').hide();
	    				if (data == 403) {
	    					alert("用户名或密码错误");
	    					return;
	    				}
    				
    				if (data == 209) {
    					location.href="${pageContext.request.contextPath}/manager";
    					return;
    				}
    				
    				if (data == 203){
    					location.href="${pageContext.request.contextPath}/property";
    					return;
    				}
    				
    				if(data.objectId != null){
    					var subaccount = data.subAccountSid;
    					var subaccountpwd = data.subToken;
    					var voipid = data.voipAccount;
    					var voippwd = data.voipPwd;
    					var villageId = data.loginVillage.objectId;
    					var clientId = data.objectId;
    					location.href="${pageContext.request.contextPath}/center?subaccount="+
    							subaccount+"&subaccountpwd="+subaccountpwd+"&voipid="+voipid+"&voippwd="+voippwd+"&vid="+villageId+"&cid="+clientId;
    				}
    			
    			});
    		}
    	
    	function keyLogin(){
   		 if (event.keyCode==13){ 
   	     	doLogin();
   		 }
   	}
    </script>
</body>
</html>